/*
 * SharedPointer.h
 *
 *  Created on: 24/ott/2010
 *      Author: computer
 */

#ifndef SHAREDPOINTER_H_
#define SHAREDPOINTER_H_
#include "AutoPointer.h"

template<class T> class SharedPointer {
	public:
		SharedPointer(T* p = 0) : ptr(p) { }
		SharedPointer(const AutoPointer<T>& copy) {
			ptr = copy.get();
		}
		SharedPointer(const SharedPointer<T>& copy) {
			ptr = copy.ptr;
		}
		~SharedPointer() {
			//if (ptr) delete ptr;
		}

		SharedPointer& operator=(const SharedPointer<T>& snd) {
			if (ptr) delete ptr;
			ptr = snd.ptr;
			return *this;
		}

		T* operator->() const {
			return ptr;
		}

		T& operator*() const {
			return *ptr;
		}

		T* get() const { return ptr; }

	private:
		T* ptr;
};



#endif /* SHAREDPOINTER_H_ */
